//
//  DiscoverViewCell.m
//  SinaWebo
//
//  Created by 亦心 on 16/7/12.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "DiscoverViewCell.h"
#import "CardGroup.h"
#import "DiscoverGroup.h"
#import "Hairline.h"

@interface DiscoverViewCell ()
@property (nonatomic, strong) NSMutableArray *viewArray;
@end
@implementation DiscoverViewCell

- (NSMutableArray *)viewArray{
    if (_viewArray == nil) {
        _viewArray = [NSMutableArray array];
    }
    return _viewArray;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self ) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initView];
    }
    return self;
}

- (void)initView{
    for (NSInteger index = 0; index < 4; index++) {
        CGFloat margin = 20;
        CGFloat paging = 10;
        CGFloat width = (kScreenW - margin * 2 - paging) * 0.5;
        CGFloat height = 44;
        UILabel *lable = [[UILabel alloc] init];
        lable.textAlignment = NSTextAlignmentLeft;
        lable.font = [UIFont systemFontOfSize:15];
        lable.x = margin + (width + paging) * (index % 2);
        lable.y =  index / 2 * height;
        lable.width = width;
        lable.height = height;
        [self.contentView addSubview:lable];
        [self.viewArray addObject:lable];
        
        if (index % 2 == 0) {
            Hairline *line = [[Hairline alloc] init];
            line.size = CGSizeMake(0.5, height * 0.8);
            line.center = CGPointMake(CGRectGetMaxX(lable.frame), lable.center.y);
            [self.contentView addSubview:line];
        }

    }
    
    Hairline *line = [[Hairline alloc] init];
    line.frame = CGRectMake(0, 44, kScreenW, 0.5);
    [self.contentView addSubview:line];
    
}

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    for (NSInteger index = 0; index < dataArray.count; index++) {
        DiscoverGroup *disGroup = dataArray[index];
        UILabel *lable = self.viewArray[index];
        lable.text = disGroup.title_sub;
    }
}

@end
